package karma.main;

import net.minecraft.client.Minecraft;
import net.minecraft.src.*;

public class ItemHellBoots extends ItemArmor
{
    public static boolean meteor;
    public static int cooldown = 0;
    public static boolean notify = true;
    public static int timer = 0;
    public static boolean worn;

    public ItemHellBoots(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
    {
        super(i, enumarmormaterial, j, k);
    }

    /**
     * Return an item rarity from EnumRarity
     */
    public EnumRarity getRarity(ItemStack itemstack)
    {
        return mod_KarmaCraft.ENCHANTED;
    }

	public static void checkIfWorn(Minecraft minecraft)
    {
        if (minecraft.thePlayer.inventory.armorInventory[0] != null && minecraft.thePlayer.inventory.armorInventory[0].getItem() == mod_KarmaCraft.HellBoots)
        {
            doSpecial(minecraft);
            worn = true;
        }
        else
        {
        	worn = false;
        }
    }

	public static void doSpecial(Minecraft minecraft)
	{
		EntityPlayer player = minecraft.thePlayer;
		World world = minecraft.theWorld;
		if(player.fallDistance > 3 && player.isSneaking())
		{
			meteor = true;
		}
		if(!player.isSneaking())
		{
			meteor = false;
		}
		
		if(meteor && player.onGround && cooldown == 0 && player.inventory.hasItem(mod_KarmaCraft.MagicPowder.shiftedIndex))
		{
			int x = (int) player.posX - 1;
			int y = (int) (player.posY - 2);
			int z = (int) player.posZ;

			world.setBlockWithNotify(x, y, z, 0);
			if (ItemHellHelm.worn)
			{
				world.setBlockWithNotify(x - 1, y, z, Block.fire.blockID);
				world.setBlockWithNotify(x - 1, y, z + 1, Block.fire.blockID);
				world.setBlockWithNotify(x - 1, y, z - 1, Block.fire.blockID);
				world.setBlockWithNotify(x, y, z - 1, Block.fire.blockID);
				world.setBlockWithNotify(x, y, z + 1, Block.fire.blockID);
				world.setBlockWithNotify(x + 1, y, z + 1, Block.fire.blockID);
				world.setBlockWithNotify(x + 1, y, z - 1, Block.fire.blockID);
				world.setBlockWithNotify(x + 1, y, z, Block.fire.blockID);
				world.setBlockWithNotify(x + 2, y, z, Block.fire.blockID);
				world.setBlockWithNotify(x - 2, y, z, Block.fire.blockID);
				world.setBlockWithNotify(x, y, z + 2, Block.fire.blockID);
				world.setBlockWithNotify(x, y, z - 2, Block.fire.blockID);
			}
			else if (!ItemHellHelm.worn)
			{
				world.setBlockWithNotify(x - 1, y, z, 0);
				world.setBlockWithNotify(x - 1, y, z + 1, 0);
				world.setBlockWithNotify(x - 1, y, z - 1, 0);
				world.setBlockWithNotify(x, y, z - 1, 0);
				world.setBlockWithNotify(x, y, z + 1, 0);
				world.setBlockWithNotify(x + 1, y, z + 1, 0);
				world.setBlockWithNotify(x + 1, y, z - 1, 0);
				world.setBlockWithNotify(x + 1, y, z, 0);
				world.setBlockWithNotify(x + 2, y, z, 0);
				world.setBlockWithNotify(x - 2, y, z, 0);
				world.setBlockWithNotify(x, y, z + 2, 0);
				world.setBlockWithNotify(x, y, z - 2, 0);
			}
			cooldown = 100;
			player.inventory.consumeInventoryItem(mod_KarmaCraft.MagicPowder.shiftedIndex);
			meteor = false;
		}
		else if (meteor && !player.inventory.hasItem(mod_KarmaCraft.MagicPowder.shiftedIndex))
		{
			if(notify)
			{
				player.addChatMessage("Not enough Magic Powder to use Hell Smash!");
				notify = false;
				timer = 20;
			}
		}
		if (cooldown > 0)
		{
			cooldown --;
		}
		if (timer > 0)
		{
			timer --;
			if (timer == 0)
			{
				notify = true;
			}
		}
	}
}
